package echat.future.cn.echat.my.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.databinding.ActivityRemindZhuboBinding;
import echat.future.cn.echat.my.adapter.RemindZhuboAdapter;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.PlanList;
import echat.future.cn.echat.my.bean.RemindUserBean;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.StatusBarUtils;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;

/**
 * 推荐的主播
 */
public class RemindZhuboActivity extends BaseActivity<ActivityRemindZhuboBinding>{

    RemindZhuboAdapter adapter;

    private List<RemindUserBean> mData = new ArrayList<>();

    @Override
    public int layoutId() {
        return R.layout.activity_remind_zhubo;
    }

    @Override
    public IBaseNavagation navagation() {
        return null;
    }

    @Override
    public void initView() {
        adapter = new RemindZhuboAdapter(this.mData);
        bind.recyclerView.setAdapter(adapter);
        bind.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        load(1);
        adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                page++;
                load(page);
            }
        },bind.recyclerView);
    }


    private int page = 1;

    private void load(int page){
        new HttpUtilsRequst<PlanList>(this,HttpUtilsRequst.retrofitClient.create(UserApi.class).planList(UserHelper.getToken(),String.valueOf(page)))
                .setmOnRequstSuccessListener((HttpUtilsRequst.OnRequstSuccessListener<PlanList>) planList -> {
                    if(page == 1){
                        mData.clear();
                    }
                    adapter.loadMoreComplete();
                    bind.all.setText(planList.getList_anchor_num());
                    bind.all.setText(planList.getContribution_left());
                    bind.diving.setText(planList.getContribution_total());
                    bind.recharge.setText("0人");
                    if(planList.getList_anchor() == null || planList.getList_anchor().isEmpty()){
                        adapter.loadMoreEnd();
                        return;
                    }
                    mData.addAll(planList.getList_anchor());
                    adapter.notifyDataSetChanged();
                    if(planList.getList_anchor().size() <10){
                        adapter.loadMoreEnd();
                    }
                })
                .start();
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtils.hideStatus(this);
    }
}
